package graphics;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

import controller.Constants;

/**
 * Circle
 * 
 * @author Jie Zhao(288654)
 * 
 */
public class Circle extends Oval {
@Override
public String toString() {
	StringBuffer sb = new StringBuffer();
	sb.append("circle:");
	sb.append(getLineColor().getRGB()+":");
	sb.append((isFilled()?"1":"0") + ":");
	sb.append(getFilledColor().getRGB()+":");
	sb.append(getStroke().getLineWidth()+":");
	sb.append(getStartPoint().x+","+getStartPoint().y+":");
	sb.append(getEndPoint().x+","+getEndPoint().y);
	return sb.toString();
}

@Override
public void fromString(String str) {
	try{
	String[] data = str.split(":");
	if(!data[0].equals("circle"))return;
	setLineColor(new Color(Integer.parseInt(data[1])));
	setFilled(data[2].equals("1"));
	setFilledColor(new Color(Integer.parseInt(data[3])));
	setStroke(new BasicStroke(Float.parseFloat(data[4]),BasicStroke.CAP_ROUND,BasicStroke.CAP_ROUND));
	String[] point = data[5].split(",");
	setStartPoint(new Point(Integer.parseInt(point[0]),Integer.parseInt(point[1])));
	point = data[6].split(",");
	setEndPoint(new Point(Integer.parseInt(point[0]),Integer.parseInt(point[1])));
	}catch(Exception e)
	{
		if(Constants.DEBUG)e.printStackTrace();
	}
}
	@Override
	/**
	 * Draw a circle
	 */
	public void draw(Graphics g) {
		regulate();
		super.draw(g);
	}
public static void main(String[] args) {
	Circle c = new Circle();
	c.setStartPoint(new Point(12,34));
	c.setEndPoint(new Point(56,78));
	System.out.println(c);
	
	Circle c2 = new Circle();
	c2.fromString(c.toString());
	System.out.println(c2);
}
}
